const db = require("../db");

let Categorys = require("./ProductCategory");

let Products = db.defineModel("products", {
  title: db.STRING(100), // 产品名称
  manufacturer: db.STRING(100), // 厂家
  price: db.DOUBLE, // 价格
});

// 产品关联分类
Categorys.hasMany(Products, {
  foreignKey: "category_id",
  sourceKey: "id",
  as: "products",
});
Products.belongsTo(Categorys, {
  foreignKey: "category_id",
  targetKey: "id",
  as: "category",
});

// 初始产品模型
module.exports = Products;
